﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using SuperMercado.Dados.OBJ;

namespace SuperMercado.Dados
{
    public class DAO : INTF
    {
        private string S2B = ConfigurationManager.ConnectionStrings["S2B"].ConnectionString;
       
        public void InserePessoa(Pessoa pessoa)
        {
            System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(S2B);
            System.Data.SqlClient.SqlCommand command = new System.Data.SqlClient.SqlCommand();
            try
            {
                command.Connection = conn;
                command.CommandText = "INSERT INTO Pessoa(pes_email, pes_senha, pes_nome, pes_cpf, pes_rg, pes_cep, pes_endnr, pes_endcompl, pes_telefone, pes_celular, pes_nivel, pes_status)"
                + "VALUES (@pes_email,@pes_senha,@pes_nome,@pes_cpf,@pes_rg,@pes_cep,@pes_endnr,@pes_endcompl,@pes_telefone,@pes_celular,1,1)";
                command.Parameters.AddWithValue("@pes_email", pessoa.Email);
                command.Parameters.AddWithValue("@pes_senha", pessoa.Senha);
                command.Parameters.AddWithValue("@pes_nome", pessoa.Nome);
                command.Parameters.AddWithValue("@pes_cpf", pessoa.Cpf);
                command.Parameters.AddWithValue("@pes_rg", pessoa.Rg);
                command.Parameters.AddWithValue("@pes_cep", pessoa.Cep);
                command.Parameters.AddWithValue("@pes_endnr", pessoa.Endnr);
                command.Parameters.AddWithValue("@pes_endcompl", pessoa.Endcompl);
                command.Parameters.AddWithValue("@pes_telefone", pessoa.Telefone);
                command.Parameters.AddWithValue("@pes_celular", pessoa.Celular);
                conn.Open();
                command.ExecuteNonQuery();
            }
            catch (Exception ex)
            {
                throw new Exception("Erro fatal ! " + Environment.NewLine + "Motivo: " + ex.Message);
            }
            finally
            {
                conn.Close();
            }                      
        }
    }
}